import http from "@/api";
import { ResPage } from "../interface";
import { Blog, BlogMd, Subfield } from "../interface/blog";
import { MdUpload } from "../interface/common";

/**
 * @name 博客模块
 */
// * 获取博客列表
export const getBlogListApi = (pageNum: number, pageSize: number, wrapper?: Partial<Blog>) => {
	return http.post<ResPage<Blog>>(`/blog/getList/${pageNum}/${pageSize}`, wrapper);
};

export const getBlogDetailApi = (id: number) => {
	return http.get<Blog>(`/blog/getdetail/${id}`);
};

export const uploadBlogMdApi = (formData: FormData) => {
	return http.post<BlogMd>("/blog/upload", formData);
};

export const addBlogApi = (blog: Blog) => {
	return http.post<string>("/blog/create", blog);
};

export const deleteBlogApi = (id: number) => {
	return http.delete<string>(`/blog/delete/${id}`);
};

export const topBlogApi = (id: number) => {
	return http.post<string>(`/blog/top/${id}`);
};

export const cancelTopBlogApi = (id: number) => {
	return http.post<string>(`/blog/cancelTop/${id}`);
};

export const getSubfieldApi = (wrapper?: Partial<Subfield>) => {
	return http.post<ResPage<Subfield>>(`/blog/subfield/list`, { wrapper });
};

export const getSubfieldDetailApi = (id: number) => {
	return http.get<Subfield>(`/blog/subfield/detail/${id}`);
};

export const addSubfieldApi = (subfield: Partial<Subfield>) => {
	return http.post<string>(`/blog/subfield/add`, subfield);
};

export const updateSubfieldApi = (subfield: Partial<Subfield>) => {
	return http.post<string>(`/blog/subfield/update`, subfield);
};

export const removeSubfieldApi = (id: number) => {
	return http.delete<string>(`/blog/subfield/remove/${id}`);
};

export const uploadMd = (formData: FormData) => {
	return http.post<MdUpload>("/blog/upload", formData);
};

export const updateBlogApi = (blog: Partial<Blog>) => {
	return http.post<string>("/blog/update", blog);
};
